package com.sqllog.core;


import com.sqllog.config.CanalClientConfig;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * Canal 客户端抽象类
 *
 * @author chennengcheng
 * @date 2020-08-24 17:36
 * @remark
 */

@Slf4j
public abstract class AbstractCanalClient implements CanalClient {

    /**
     * canal 配置
     */
    private CanalClientConfig serverInstance;

    private String status;

    /**
     * 构造方法，初始化 canal 的配置以及转换信息的工厂实例
     */
    protected AbstractCanalClient(CanalClientConfig serverInstance) {
        //参数校验
        Objects.requireNonNull(serverInstance, "canalConfig 不能为空!");
        //初始化配置
        this.serverInstance = serverInstance;
    }

    /**
     * 开启 canal 客户端
     */
    @Override
    public void start(Thread.UncaughtExceptionHandler exceptionHandler){
        this.process(this.serverInstance, exceptionHandler);
    }

    /**
     * 初始化 canal 连接
     *
     * @param serverInstance
     */
    protected abstract void process(CanalClientConfig serverInstance, Thread.UncaughtExceptionHandler exceptionHandler);

}